﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;

namespace HelpDeskTicketingApp.Models
{
    public static class EmailManager
    {
        private static readonly string From = "YourBudget@outlook.com";
        public static string To { get; set; }
        public static string Subject { get; set; }
        public static string Body { get; set; }
        private static SmtpClient _client;
        private static readonly string UserName = "YourBudget@outlook.com";
        private static readonly string Password = "!BudgetBills123";
        private static readonly int Port = 587;
        private static readonly string Host = "smtp-mail.outlook.com";


        static EmailManager()
        {
            _client = new SmtpClient(Host, Port);
            _client.UseDefaultCredentials = false;
            _client.Credentials = new System.Net.NetworkCredential(UserName, Password);
            _client.EnableSsl = true;
        }

        public static bool SendEmail()
        {
            MailMessage mail = new MailMessage(From, To, Subject, Body);
            try
            {
                _client.Send(mail);
                return true;
            }
            catch (Exception x)
            {
                return false;
            }
        }

        public static bool SendNewEmail(string userName, string email, string description, DateTime dateDue,
            decimal amount)
        {
            Subject = "You have created a new Budget Item";
            Body = "Dear, " + userName;
            Body += "You have added a new bill or income event to your budget.";
            Body += "Don't forget to add it to your calendar so you won't forget!";
            Body += "Date Due: " + dateDue;
            Body += "Amount: " + amount;
            Body += "Description: " + description;

            if (email == null)
            {
                email = From;
            }
            MailMessage mail = new MailMessage(From, email, Subject, Body);
            try
            {
                _client.Send(mail);
                return true;
            }
            catch (Exception x)
            {
                return false;
            }
        }
    }
}